﻿<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>生产计划</title>
    <meta name="renderer" content=padding>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/Scripts/formSelect/multiSelect.js"></script>
    <script type="text/html" id="barDemo">
        <a title="编辑修改" href="javascript:;"  lay-event="edit" id="frmEdit"><i class="layui-icon">&#xe642;</i></a>
        <a title="生产工艺" href="javascript:;"  lay-event="setGy" id="frmGy"><i class="layui-icon">&#xe60a;</i></a>
        <a title="计划图纸" href="javascript:;"  lay-event="plPic" id="frmPic"><i class="layui-icon">&#xe60d;</i></a>
        <a title="原辅料占用" href="javascript:;"  lay-event="yflzy" id="frmZy"><i class="layui-icon">&#xe61e;</i></a>
        <a title="计划删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
       
        
    </script> 
</head>
<body>
    <div class="layui-fluid" style="width:100%;">
        <div id="bDiv">
        </div>
        <div style="float:left;width:100%;">
            <div class="layui-card" >

                <div class="layui-card-body" style="margin-top:5px">
                    <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="plCode" placeholder="计划编码" autocomplete="off" class="layui-input" id="plCode">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="erpOrder" placeholder="订单编码" autocomplete="off" class="layui-input" id="erpOrder">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="cuName" placeholder="关联客户" autocomplete="off" class="layui-input" id="cuName">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="hidden" name="cStatus" id="cStatus">
                            <select multiple="multiple" lay-filter="multiple" id="status" name="status"></select>
                        </div>
                    </form>
                </div>
                <div>
                    <span style="margin-left: 20px; padding: 7px; background-color: #FFB54C;font-size:Xx-small">即将逾期</span>
                    <span style="margin-left: 20px; padding: 7px; background-color: #FF7C7C;font-size:Xx-small">已逾期</span>
                    <span style="margin-left: 20px; padding: 7px; background-color: #C3FDB8;font-size:Xx-small">已完成</span>
                </div>

                <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                    <table class="layui-hide" id="list" lay-filter="list"></table>
                </div>
            </div>


        </div>
    </div>
</body>
</html>
<script src="~/js/framework/sysframework.js"></script>
<script src="~/js/framework/commonjs.js"></script>
<script src="~/js/sysweb/planjs.js"></script>
<script>
    var webCode = "";
    
    var selectList = new Array();

    $(function () {
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");
        DictionaryDropDown("pst", "status", "", true);
        loadData();
    })
    function openQueryWin() {
        gjQuery=true;
        InfoOpenPage("../System/QueryWeb?webCode=" + webCode, "高级检索", "85%", "80%");
    }
    function openWin() {
        InfoOpenPage("../Plan/UpdatePlanNew?dataId=0", "创建计划", "85%", "80%",true);
    }

  
    layui.use(['multiSelect'], function () {
        var $ = layui.jquery, form = layui.form, multiSelect = layui.multiSelect;
    });
    /**
     * 获取多选的状态
     */
    function GetSelectMore() {
        var vals = [], 
            texts = [];
        $('select[multiple] option:selected').each(function () {
            vals.push($(this).val());
            texts.push($(this).text());
        })
        $("input[ name='cStatus']").val(vals.join(','));

    }

    var cData = new Array();
    var dUrl = "../Plan/getDataList?dataType=plan&condition=";
    /**
     * 加载数据
     * **/
    function loadData(){
        GetSelectMore();

        cData = new Array();

        if(!gjQuery){
            qStr = FormToJson("qForm");
        }

        gjQuery=false;
        layui.use('table', function () {
            var conditon = JSON.stringify(qStr);
            var table = layui.table;
            if (conditon.includes("#")) {
                conditon = conditon.replace(/\#/g, "%23");
            }
            table.render({
                elem: '#list'
                , height: 'full-200'   //固定高度-即固定表头固定第一行首行
                , cols: [[ //标题栏
                    { type: 'checkbox' },
                    {field: 'plCode', align: 'center', title: '计划编码', width: 120, sort: true }
                    , { field: 'erpOrder', align: 'center', title: '销售订单号', width: 120, sort: true }
                    , { field: 'proCode', align: 'center', title: '存货编码', width: 100 }
                    , { field: 'proName', align: 'center', title: '存货名称', width: 170 }
                    , { field: 'spec', align: 'center', title: '规格', width: 100 }
                    , { field: 'number', align: 'center', title: '生产数量', width: 100 }
                    , { field: 'cuName', align: 'center', title: '关联客户', width: 120 }
                    , { field: 'gcName', align: 'center', title: '生产工厂', width: 120 }
                    , { field: 'memo', align: 'center', title: '备注', width: 110 }
                    , { field: 'statusName', align: 'center', title: '计划状态', width: 90 }
                    , { field: 'jfDate', align: 'center', title: '交付日期', width: 100 }
                    , { field: 'finishDate', align: 'center', title: '完成日期', width: 100 }
                    , { field: 'userName', align: 'center', title: '创建人', width: 100 }
                    , { field: 'createtime', align: 'center', title: '创建时间', width: 150, sort: true }
                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: 120, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    // $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    TablePowerHide();
                    $.each(res['data'], function (i, j) {
                        if (j["remindType"]=="1") {
                            //console.log("需要提醒")
                            TableRowColor('layui-table-main', i, '#FFB54C');
                        }
                        if (j["remindType"] == "2") {
                            //console.log("已逾期")
                            TableRowColor('layui-table-main', i, '#FF7C7C');
                        }
                        if (j['status'] == "ps-finish") {
                            TableRowColor('layui-table-main', i, '#C3FDB8');
                        }
                    });
                }
                , url: dUrl + conditon
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [20, 25, 30]
                , limit: 20 //每页默认显示的数量
                , id: "list"
            });

            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if ((obj.event == 'edit' || obj.event == 'del') && data.status == "ps-doing") {
                    layer.msg('计划已派工，禁止操作', { icon: 2 }); return;
                }
                if (obj.event == 'del') {
                    if (data.status != 'ps-pg-set') {
                        layer.msg("计划此状态禁止删除", { icon:2 }); return;
                    }
                    layer.confirm('确认要删除' + data.plCode + '？', {icon:3}, function (index) {
                        var info = DelData(data.plCode, data.status);
                        if (info.result) {
                            layer.msg("删除成功");
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });
                } 
                else if (obj.event == 'edit') {
                    if (data.status == "ps-finish") {
                        layer.msg('计划已完工，禁止修改'); return;
                    }
                    var webUrl = "../Plan/UpdatePlanNew?dataId=" + data.plCode;
                    var title = data.plCode + "-计划修改";
                    NewOpenPage(webUrl, title, "95%", "90%", "list", currPage, dUrl + conditon);
                } 
                else if (obj.event == 'setGy') {
                    var webUrl = "../Plan/UpdatePlanGY?plCode=" + data.plCode+"&isRead=0" ;
                    var title = data.plCode + "-计划工艺";
                    NewOpenPage(webUrl, title, "95%", "90%", "list", currPage, dUrl + conditon);
                } 
                else if (obj.event == 'yflzy') {
                    var webUrl = "../Plan/MaterialOccupy?plCode=" + data.plCode + "&proCode=" + data.proCode + "&planNum=" + data.number + "&proName=" + data.proName + "&spec=" + data.spec + "&cuName=" + data.cuName;
                    var title = data.plCode + "-"+data.proName
                    NewOpenPage(webUrl, title, "98%", "98%", "list", currPage, dUrl + conditon);
                } else if (obj.event == 'plPic') {
                    var webUrl = "../Plan/UploadPlanFile?plCode=" + data.plCode;
                    var title = data.plCode + "-" + data.plCode
                    NewOpenPage(webUrl, title, "95%", "90%", "", currPage, dUrl + conditon);
                }
              
            });

            /**复选框**/
            table.on('checkbox(list)', function (obj) {
                var select = new Array();
                var checkStatus = table.checkStatus('list');

                for (var i = 0; i < checkStatus.data.length; i++) {
                    select.push(checkStatus.data[i]);
                }
                cData = select;
            });
  

            // 绑定双击事件
            table.on('rowDouble(list)', function (obj) {

                var webUrl = "../Plan/PlanDetail?plCode=" + obj.data.plCode;
                var title = obj.data.plCode + "-计划详情";
                NewOpenPage(webUrl, title, "95%", "90%", "", "", "");
            });

        });

    }

    var qStr="";
    /**
     * 获取高级查询字符串
     * **/
    function GetQueryPar(queryStr) {
      qStr=queryStr;
      loadData();
    }

    /**
     * 计划派工
     * **/
    function PaiGong() { 
        if (cData.length > 0) {
            $.ajax({
                url: "../Plan/PlanPaiGong",
                data: { datas: JSON.stringify(cData) },
                type: "post",
                success: function (data) {
                    if (data.result) {
                        layer.alert("计划已派工", { icon: 6 });
                        loadData();
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
        }
    }

    /**
     * 取消派工
     * **/
    function CancelPg() {
        if (cData.length > 0) {
            $.ajax({
                url: "../Plan/PlanCancelPaiGong",
                data: { datas: JSON.stringify(cData) },
                type: "post",
                success: function (data) {
                    if (data.result) {
                        layer.alert("计划已取消派工", { icon: 6 });
                        loadData();
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
        }
    }

    /**
    * 计划完成
    * **/
    function finishPlan() {
        if (cData.length > 0) {
            layer.confirm('确定要完成选中计划？', function (index) {
                $.ajax({
                    url: "../Plan/finishPlan",
                    data: { datas: JSON.stringify(cData) },
                    type: "post",
                    success: function (data) {
                        if (data.result) {
                            layer.alert("计划已完成", { icon: 6 });
                            loadData();
                        } else {
                            layer.msg(data.message);
                        }
                    }
                });

            });
        }
    }
    


</script>
